package com.bjc.netty.c2;

import io.netty.channel.DefaultEventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;

/**
 * @program: nettypro
 * @description: EnventLoop
 * @author: bjc
 * @create: 2021-09-21 21:38
 */
@Slf4j
public class TestEventLoop {

    public static void main(String[] args) {
        // 1.创建事件循环组
        NioEventLoopGroup group = new NioEventLoopGroup(2); //io事件 普通任务 定时任务
//        DefaultEventLoopGroup group = new DefaultEventLoopGroup(); // 普通任务 定时任务
        //2.获取下一个事件循环对象
        System.out.println(group.next());
        System.out.println(group.next());
        System.out.println(group.next());
        System.out.println(group.next());

        //3.执行普通任务
        group.next().execute(() -> {
            try {
                TimeUnit.SECONDS.sleep(1L);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            log.debug("ok");
        });

        //4.执行定时任务
        group.next().scheduleAtFixedRate(() -> {
            log.debug("okk");
        }, 0, 1, TimeUnit.SECONDS);
        log.debug("main");
    }
}
